var result = [];
var currentQuizIndex = 0;
var isEnded = false;

function checkEnd() {
	if (currentQuizIndex >= quizLength) {//做完题了
		isEnded = true;
		// 创建一个 form
		var form = document.createElement("form");
		form.id = "form";
		form.name = "form";

		// 添加到 body 中
		document.body.appendChild(form);

		// 创建一个输入
		let input = document.createElement("input");
		// 设置相应参数
		input.type = "text";
		input.name = "result";
		input.value = result;

		// 将该输入框插入到 form 中
		form.appendChild(input);

		// form 的提交方式
		form.method = "POST";
		// form 提交路径
		if (part == 1) {
			form.action = "test1.jsp";
		}
		else if (part == 2) {
			form.action = "result.jsp";
		}

		// 对该 form 执行提交
		form.submit();
		// 删除该 form
		document.body.removeChild(form);
	}
}

function know() {
	if (!isEnded) {
		result[currentQuizIndex] = 1;
		currentQuizIndex++;
		document.getElementById("testedNum").innerHTML = "已测试" + (part==1?currentQuizIndex:currentQuizIndex+20) + "个单词";
		checkEnd();
		if(!isEnded){
			document.getElementById("quiz").innerHTML = w[currentQuizIndex];
		}
	}
}

function dontKnow() {
	if (!isEnded) {
		result[currentQuizIndex] = 0;
		currentQuizIndex++;
		document.getElementById("testedNum").innerHTML = "已测试" + (part==1?currentQuizIndex:currentQuizIndex+20) + "个单词";
		checkEnd();
		if(!isEnded){
			document.getElementById("quiz").innerHTML = w[currentQuizIndex];
		}
	}
}